#!/bin/bash
#
# Runs per-user scripts for managing the contents of individual user accounts,
# typically by running this command at login time using XDG autostart (in
# graphical environments) or by supplying this command in default .bashrc
# scripts in /etc/skel (for CLI-only environments). Scripts that are run by
# this command are expected to be run as regular users, not as root.
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 19 December 2012
#
#   Copyright 2012 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

function show_help() {
   cat << EOF
Usage: run-user-scripts

Runs any per-user scripts specified by the system administrator. This command
should be run as a regular user, NOT as root.
EOF
}


function show_summary() {
   echo "Runs per-user scripts"
}

ARGS=$(getopt -o "k:" -l "help,shorthelp" \
              -n "$0" -- "$@")
if [ $? -ne 0 ]; then
   exit 2
fi

eval set -- "$ARGS"

while [ ! "$1" = "--" ]; do
   case "$1" in
      --help)
         shift
         show_help
         exit 0
      ;;
      --shorthelp)
         shift
         show_summary
         exit 0
      ;;
   esac
done

shift


if [ $# -ne 0 ]; then
   echo "Command usage: pulley run-user-scripts" >&2
   exit 2
fi

scriptroot="${PULLEY_COMMAND_DIR}/get-context pulley_user_scripts"
if [ -n "${scriptroot}" -a -d "${scriptroot}" ]; then
   run-parts "${scriptroot}"
fi
